package org.hsieh.tr.explore.dbsource.impl;

import java.sql.SQLException;
import java.util.List;

import org.hsieh.tr.explore.annotation.TreeNodeChildren;
import org.hsieh.tr.explore.annotation.TreeNodeLabel;
import org.hsieh.tr.explore.dbsource.ISchemaEntity;
import org.hsieh.tr.explore.dbsource.ITableColumnEntity;
import org.hsieh.tr.explore.dbsource.ITableEntity;

public class TableEntityImpl extends AbstractDBObj implements ITableEntity {

    private ISchemaEntity schema;

    private String name;

    private List<ITableColumnEntity> columns;

    public String type;

    @TreeNodeLabel(image = "icons/db/tr_table.png")
    public String getName() {
	return name;
    }

    public ISchemaEntity getSchema() {
	return schema;
    }

    @TreeNodeChildren
    public List<ITableColumnEntity> getTableColumns() throws SQLException {
	if (columns == null) {
	    columns = findTableColumns(this);
	}
	return columns;
    }

    public List<ITableColumnEntity> getColumns() {
	return columns;
    }

    public void setSchema(ISchemaEntity schema) {
	this.schema = schema;
    }

    public void setName(String name) {
	this.name = name;
    }

    @Override
    public String toString() {
	return "TableEntityImpl [name=" + name + "]";
    }

    public String getType() {
	return type;
    }

    public void setType(String type) {
	this.type = type;
    }

    @Override
    public void refresh() {
	this.columns = null;
    }
}
